/*分类信息*/
import {defineStore} from "pinia";
import {topCategory} from "@/api/static";
import {getAllCategory} from "@/api/category";

export const useCategoryStore=defineStore("category",{

    state:()=>{
        return{
            List:topCategory.map(item=>({
                name:item
            }))
        }
    },
    persist:true,
    actions:{
        // 获取所有分类
        async getCategoryList(){
            const {result}=await getAllCategory()
            result.forEach(top=>top.open=false)
            this.List=result
        },
    // 显示二级菜单
        show(id){
        const currCategory=this.List.find(item=>item.id===id)
            currCategory.open=true
        },
    // 隐藏二级菜单
        hide(id){
            const currCategory=this.List.find(item=>item.id===id)
            currCategory.open=false
        }
    },
})